package com.kent.hellokotlin.cClassAndObject

//枚举类

enum class Direction {
    NORTH, SOUTH, WEST, EAST
}

enum class Color(val rgb: Int) {
    RED(0xff0000),
    GREEN(0x00ff00),
    BLUE(0x0000ff)
}


enum class ProtocolState {
    TALKING {
        override fun nextState() = WAITING
    },
    WAITING {
        override fun nextState() = TALKING
    };

    abstract fun nextState(): ProtocolState
}

interface StateMachine {
    fun nextState(): StateMachine
}

enum class State1 : StateMachine {
    Talking {
        override fun nextState() = Waiting
    },

    Waiting {
        override fun nextState() = Talking
    }
}

enum class State2 : StateMachine {
    Talking,

    Waiting;

    override fun nextState(): StateMachine {
        return if (this == Talking) {
            Waiting
        } else {
            Talking
        }
    }
}

private fun foo() {
    val nextState = State2.valueOf("Waiting").nextState()
    println(nextState)
    println("---------------------------------------------------------------------------------------")
    for (value in State2.values()) {
        println(value)
    }
    println("---------------------------------------------------------------------------------------")
    println(enumValueOf<ProtocolState>("TALKING").nextState())
    println("---------------------------------------------------------------------------------------")
    for (enumValue in enumValues<ProtocolState>()) {
        println(enumValue)
    }
    println("---------------------------------------------------------------------------------------")
    println("red name: ${Color.RED.name}, index: ${Color.RED.ordinal}")
}

fun main() {
    foo()
}